using System;
using System.Text;
using ToffeeHttp.Runtime.Core;
using UnityEngine.Networking;

namespace ToffeeHttp.Runtime
{
    /// <summary>
    /// Post网络请求，且使用Json的形式传输
    /// </summary>
    public class PostHandlerJson : IRequestHandler
    {
        
        public UnityWebRequest RequestCreate(Uri uri, object msg)
        {
            UnityWebRequest  requestU = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbPOST);
            byte[]           bytes    = Encoding.UTF8.GetBytes((string) msg);
            UploadHandlerRaw uH       = new UploadHandlerRaw(bytes);
            uH.contentType           = "application/json";
            requestU.uploadHandler   = uH;
            requestU.downloadHandler = new DownloadHandlerBuffer();
            return requestU;
        }

    }
}